﻿// This code is released under the BSD license.
namespace PugLib.UI.Controls
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public partial class CustomMessageBoxButton : UserControl
    {
        private readonly string _description;
        private readonly string _label;

        private CustomMessageBoxButton()
        {
            InitializeComponent();
        }

        public CustomMessageBoxButton(Image image, string textPrimary, string textSecondary)
            : this()
        {
            btnPugDialogButton.Values.Image = image;
            _label = textPrimary;
            _description = textSecondary;

            UpdateButtonText();
        }

        public string Result { get { return _label; } }


        private void UpdateButtonText()
        {
            btnPugDialogButton.Text = _label;
            btnPugDialogButton.Values.ExtraText = _description;
        }


        private void btnPugDialogButton_Click(object sender, EventArgs e)
        {
            Form parentForm = FindForm();
            if (parentForm == null)
            {
                return;
            }

            CustomMessageBox parent = parentForm as CustomMessageBox;
            if (parent == null)
            {
                return;
            }

            parent.Result = Result;
            parentForm.Close();
        }
    }
}